﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ConnectionManager
/// </summary>
public class ConnectionManager
{
    private static SqlConnection con;
    private static SqlCommand sqlCmd;
    public static void CreateConnection()
    {
        string conString = ConfigurationManager.ConnectionStrings["SQLDbConnection"].ConnectionString;
        con = new SqlConnection(conString);
        //con = new SqlConnection(@" Data Source=.\SQLEXPRESS;
                                                //Initial Catalog=WebsitePractice;
                                                //Integrated Security=True ");

        if (con.State == System.Data.ConnectionState.Closed)
            con.Open();
    }

    public static void ExecuteQueries(string query)
    {
        CreateConnection();
        sqlCmd = new SqlCommand(query, con);
        sqlCmd.ExecuteNonQuery();
    }

    public static SqlDataReader ExecuteReader(string query)
    {
        CreateConnection();
        sqlCmd = new SqlCommand(query, con);
        SqlDataReader rd = sqlCmd.ExecuteReader();
        return rd;
    }
}